package com.longkey.workflow.client.selector
{
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.collections.ICollectionView;
	import mx.core.IVisualElement;
	import mx.managers.PopUpManager;
	
	import spark.components.BorderContainer;
	import spark.components.Button;
	import spark.components.Group;
	import spark.components.HGroup;
	import spark.components.Scroller;
	import spark.layouts.VerticalLayout;
	
	public class ConfirmSelector extends BorderContainer
	{
		private var _selector:ISelector;
		private var _callback:Function;
		
		private var _confirmBtn:Button;
		private var _cancelBtn:Button;
		
		public function ConfirmSelector(selector:ISelector)
		{
			super();
			var lay:VerticalLayout = new VerticalLayout();
			lay.paddingBottom = 5;
			lay.paddingLeft = 5;
			lay.paddingRight = 5;
			lay.paddingTop = 5;
			lay.gap = 0;
			this.layout = lay;
			
			this.setStyle("cornerRadius", 20);
			this.setStyle("dropShadowVisible", true);
			
			this._selector = selector;
			var scroller:Scroller = new Scroller();
			scroller.viewport = this._selector as Group;
			scroller.percentHeight = 100;
			scroller.percentWidth = 100;
			this.addElement(scroller);
			
			this._confirmBtn = new Button();
			this._confirmBtn.label = "确定";
			this._confirmBtn.addEventListener(MouseEvent.CLICK, submit);
			this._cancelBtn = new Button();
			this._cancelBtn.label = "取消";
			this._cancelBtn.addEventListener(MouseEvent.CLICK, cancel);
			var g:HGroup = new HGroup();
			g.height = 30;
			g.percentWidth = 100;
			g.verticalAlign = "middle";
			g.horizontalAlign = "center";
			g.gap = 10;
			g.addElement(this._confirmBtn);
			g.addElement(this._cancelBtn);
			
			this.addElement(g);
		}
		
		public function get selector():ISelector{
			return this._selector;
		}
		
		public function set callback(callback:Function):void{
			this._callback = callback;
		}
		
		private function submit(event:MouseEvent):void{
			if(this._selector != null){
				var result:Object = this._selector.submit();
				this._callback(result);
			}
			PopUpManager.removePopUp(this);
		}
		
		private function cancel(event:MouseEvent):void{
			PopUpManager.removePopUp(this);
		}
	}
}